/**
 * @file s_sample.h
 * @brief 
 * @author xuesong (wenshaoliu@foxmail.com)
 * @version 1.0
 * @date 2023-12-05
 * 
 * @copyright Copyright (c) 2023  by xuesong
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2023-12-05     <td>1.0     <td>xuesong   <td>内容
 * </table>
 */
#ifndef __S_SAMPLE_H_
#define __S_SAMPLE_H_

#include "types.h"
//-------------------------------------------------------------------------
typedef union {
    struct
    {
        unsigned char subNegative		        : 1;    // 
    }Bit;
    uint8_t Byte;
}adcFilterFlag_t;
//-------------------------------------------------------------------------
typedef enum
{
    NOT_WATER,
    ADD_WATER,
    SUB_WATER,
}WATER_FLOW_TYPE;
typedef struct{
	union {
        struct
        {
            unsigned char WaterAdcAdd        : 1;    // 
            unsigned char WaterFlowIng       : 1;    // 
            unsigned char WaterFlowRest      : 1;    // 
            unsigned char StopTrig          : 1;    // 
        }Bit;
        uint8_t Byte;
    }Flag;
    uint8_t  WaterType;
    uint8_t  stopCnt;
    uint8_t  litterCnt;
    uint8_t  MiddleCnt;
    uint32_t lastFiltAdc;
}WaterFlow_t;
extern WaterFlow_t  waterFlow; 
//-------------------------------------------------------------------------
typedef struct{
	union {
        struct
        {
            unsigned char init 		        : 1;    // 
            unsigned char CheckReg          : 1;    // 
            unsigned char AdcInterruptNew   : 1;    //
            unsigned char adcNew            : 1;    //
            unsigned char SampleNew         : 1;    //
            unsigned char resetFilter       : 1;    //
            unsigned char middleFilter      : 1;    // 启用中位值滤波
            unsigned char lock              : 1;    //
            unsigned char locked            : 1;    //
            unsigned char AutoStartRest     : 1;    // 自动识别重置 滤波值
        }Bit;
        uint16_t Byte;
    }Flag;
    uint32_t Adc;                                   //read Adc value
    uint32_t FilterAdc;                             //Filter Adc
    uint32_t DisplayAdc;                            //外部使用Adc
}userAdc_t;
extern userAdc_t   userAdcStruct;
//-------------------------------------------------------------------------
typedef struct{
	union {
        struct
        {
            unsigned char init 		                : 1;    // 
            unsigned char CalOK                     : 1;    //
            unsigned char ZeroOK                    : 1;    //
            unsigned char WtEnable                  : 1;    //
            unsigned char WtNew                     : 1;    //
            unsigned char Load                      : 1;    //
            unsigned char Lock                      : 1;    //
            unsigned char overLoad                  : 1;    //
            unsigned char AutoTare                  : 1;    // 启用自动去皮
            unsigned char tare                      : 1;    // 待去皮
            unsigned char tared                     : 1;    // 已去皮
            unsigned char Calibration               : 1;    // 标定中
            unsigned char CalibrationAutoZrEn       : 1;    // 标定 自动找零 使能
        }Bit;
        uint16_t Byte;
    }Flag;
    uint16_t DivisionAdc;
    uint32_t ZeroPointADC;
    uint32_t TarePointADC;
    int32_t NetWeight;
    int32_t GrossWeight;
}Weight_t;
extern Weight_t ScaleWeight;
//-------------------------------------------------------------------------
// void adc_median_filter(void);
uint32_t WithoutMinMaxAverage(const uint32_t* buff,uint8_t buffLen);
void  F_DetectiveWaterFlow(void);
//-------------------------------------------------------------------------

#endif